﻿using System;
using System.Windows.Forms;

namespace winform_demo._5_控件间的数据传递方式.DataBinding
{
    public partial class DBForm1 : Form
    {
        Data1 data1 = new Data1();
        Data2 data2 = new Data2();

        public DBForm1()
        {
            InitializeComponent();

            //Text属性绑定data的Content属性，单向绑定，text属性变化时更新data的Content
            textBox1.DataBindings.Add("Text", data1, "Content");
            //Text属性绑定data的Content属性，双向绑定
            textBox2.DataBindings.Add("Text",data2,"Content",true,DataSourceUpdateMode.OnPropertyChanged);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = "改变文本框内容";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            label1.Text = data1.Content;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            data1.Content = "改变data绑定项";
        }

        private void button4_Click(object sender, EventArgs e)
        {
            textBox2.Text = "改变文本框内容";
        }

        private void button5_Click(object sender, EventArgs e)
        {
            data2.Content = "改变data的Content";
        }

        private void button6_Click(object sender, EventArgs e)
        {
            label3.Text = data2.Content;
        }
    }
}
